package com.openflag.bwicservice.repository;

import com.openflag.bwicservice.domain.Bwic;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;
import java.util.Optional;

public interface BwicRepository extends JpaRepository<Bwic,Long> {

    @Query(value = "select * from bwic where created_by_id = ?1",nativeQuery = true)
    List<Bwic> getSellerBwicBySellerId(Long sellerId);



    //ERROR:JPA-style positional param was not an integral ordinal
    //原因是没有sql语句拼接时忘了多加一个空格
    @Query(value = "select * from bwic",nativeQuery = true)
    List<Bwic> getAllList();

    @Query(value = "select * from bwic where created_by_id = ?2"+
            " and id = ?1",nativeQuery = true)
    Optional<Bwic> getSellerBwicByBwicIdAndSellerId(Long BwicId, Long sellerId);

    @Query(value = "select * from bwic where status = 0",nativeQuery = true)
    List<Bwic> getUnvaluedList();

    @Query(value = "select * from bwic where status = 1",nativeQuery = true)
    Optional<List<Bwic>> getUncheckedBwicList();

    @Query(value = "select * from bwic where status = 4 or status = -1",nativeQuery = true)
    List<Bwic> getAvailableBwic();
}
